package com.denso.store.admin.administrator;

import com.denso.store.common.model.Admin;
import com.jfinal.core.Controller;

import java.util.List;

/**
 * Created by lijian on 2017/10/26.
 */
public class AdminController extends Controller {

    static final AdminService service = new AdminService();

    public void index() {
        int type = getParaToInt("type", getAttrForInt("type"));
        List<Admin> adminList = service.findByTpe(type);
        setAttr("type", type);
        setAttr("adminList", adminList);
        render("index.html");
    }

    public void add() {
        setAttr("type", getPara("type"));
        render("add.html");
    }

    public void save() {
        Admin admin = getModel(Admin.class);
        service.save(admin);
        setAttr("type", admin.getType());
        setAttr("notice", "添加成功");
        index();
    }

    public void delete() {
        int id = getParaToInt("id");
        int type = getParaToInt("type");
        service.deleteById(id);
        setAttr("type", type);
        setAttr("notice", "删除成功");
        index();
    }


}
